/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NetworkMonitorPanel.java
 *
 * Created on 29-Mar-2010, 13:07:54
 */
package neuralmusic.brain.gui;

import java.awt.BorderLayout;
import java.awt.Color;

import neuralmusic.brain.module.Brain;


import uk.co.drpj.util.tweaks.Tweakable;
import uk.co.drpj.util.tweaks.gui.TweakerPanel;

/**
 *
 * @author pjl
 */
public class NetworkMonitorPanel extends javax.swing.JPanel {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	Brain brain;
    private  TweakerPanel tweakerPanel;

    /** Creates new form NetworkMonitorPanel */
    public NetworkMonitorPanel() {
        initComponents();
    }

    /** Creates new form NetworkMonitorPanel */
    public NetworkMonitorPanel(Brain brain) {
        this();
        this.brain = brain;
        tweakerPanel=new TweakerPanel(1,brain.tweaks.size());
        controlPanel.setLayout(new BorderLayout());
        controlPanel.add(tweakerPanel,BorderLayout.CENTER);
        controlPanel.setBackground(Color.red);
        for (Tweakable tweak:brain.tweaks) {
            tweakerPanel.addSpinTweaker(tweak);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {

        queuedText = new java.awt.Label();
        label1 = new java.awt.Label();
        maxLatencyText = new java.awt.Label();
        label2 = new java.awt.Label();
        label3 = new java.awt.Label();
        avLatencyText = new java.awt.Label();
        controlPanel = new javax.swing.JPanel();

        queuedText.setAlignment(java.awt.Label.RIGHT);
        queuedText.setBackground(new java.awt.Color(254, 254, 254));
        queuedText.setText("0");

        label1.setText("Queued");

        maxLatencyText.setAlignment(java.awt.Label.RIGHT);
        maxLatencyText.setBackground(new java.awt.Color(254, 254, 254));
        maxLatencyText.setText("0");

        label2.setText("Max Latency");

        label3.setText("Av Latency ");

        avLatencyText.setAlignment(java.awt.Label.RIGHT);
        avLatencyText.setBackground(new java.awt.Color(254, 254, 254));
        avLatencyText.setText("0");

        javax.swing.GroupLayout controlPanelLayout = new javax.swing.GroupLayout(controlPanel);
        controlPanel.setLayout(controlPanelLayout);
        controlPanelLayout.setHorizontalGroup(
            controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        controlPanelLayout.setVerticalGroup(
            controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 193, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(59, 59, 59)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(avLatencyText, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(maxLatencyText, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(queuedText, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(168, Short.MAX_VALUE))
            .addComponent(controlPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(queuedText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(maxLatencyText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(avLatencyText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(controlPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.Label avLatencyText;
    private javax.swing.JPanel controlPanel;
    private java.awt.Label label1;
    private java.awt.Label label2;
    private java.awt.Label label3;
    private java.awt.Label maxLatencyText;
    private java.awt.Label queuedText;
    // End of variables declaration//GEN-END:variables

    public void myUpdate() {
        int qSize = brain.getFireQueue().size();

        queuedText.setText("" + qSize);

//        long maxlat = brain.getDelayMax();
//
//        maxLatencyText.setText("" + maxlat+"  "+TimeRef.unitname());
//
//        double ss = brain.getDelaySum();
//        long cc = brain.getFireCount();
//        
//        
//        if (cc > 0) {
//            avLatencyText.setText(String.format(" %8.2g",  ss / cc));
//        }

        repaint();
    }
}
